import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'

export const constantRoutes: Array<RouteRecordRaw> = [
    {
        path: '/main',
        name: 'main',
        component: () => import('../components/HomeView.vue'),
        redirect: '/InfoManagement',
        children: [
            {
                name: "InfoManagement",
                path: "/InfoManagement",
                component: () => import('../components/InfoManagement.vue'),
                meta: {
                    title: "信息管理",
                    icon: "User",
                    role:'user'
                },
                children: []
            },
            {
                name: "OrderManagement",
                path: "/OrderManagement",
                component: () => import('../components/OrderManagement.vue'),
                meta: {
                    title: "订单管理",
                    icon: "Service",
                    role:'user'
                },
                children: []
            },
            {
                name: "MenuManagement",
                path: "/MenuManagement",
                component: () => import('../components/MenuManagement.vue'),
                meta: {
                    title: "菜单管理",
                    icon: "DocumentCopy",
                    role:'user'
                },
                children: []
            }
        ]
    },{
        path: '/system',
        name: 'system',
        component: () => import('../components/HomeView.vue'),
        redirect: '/ShopsManagement',
        children: [
            {
                name: "ShopsManagement",
                path: "/ShopsManagement",
                component: () => import('../components/ShopsManagement.vue'),
                meta: {
                    title: "商家管理",
                    icon: "Shop"
                },
                children: []
            },
            {
                name: "DeliveryManagement",
                path: "/DeliveryManagement",
                component: () => import('../components/DeliveryManagement.vue'),
                meta: {
                    title: "外卖员管理",
                    icon: "Bicycle"
                },
                children: []
            }
            ,
            {
                name: "CabinetManagement",
                path: "/CabinetManagement",
                component: () => import('../components/CabinetManagement.vue'),
                meta: {
                    title: "外卖柜管理",
                    icon: "Files"
                },
                children: []
            }
        ]
    },
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('../components/login.vue'),
        children: []
    },{
        path: '/bgLogin',
        name: 'bgLogin',
        component: () => import('../components/bgLogin.vue'),
        children: []
    },
    {
        path: '/:catchAll',
        name: '/404',
        component: () => import('../components/404.vue'),
        children: []
    },

]


export const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    linkActiveClass: 'router-checked',
    routes: constantRoutes
})


// 白名单
//const whiteList = ['/login'] // no redirect whitelist
export const permissionsList = ['/Home', '/login', '/HomePage', '/main'] // no redirect whitelist
router.beforeEach((to, from, next) => {
    next()
    /*  if (getToken() != undefined && permissionsList.indexOf(to.path) !== -1) {
          next()
          //没有token并且是前往login页面
      } else if (getToken() == undefined && whiteList.indexOf(to.path) !== -1) {
          // 未登录,跳转到登陆页面
          next()
      } else {
          next({
              path: '/login'
          })
      }*/
})
export default router
